*****************************************************************
* Replication directory for                                   ***
* Prime locations                                             ***
* by Gabriel M. Ahlfeldt, Thilo N.H. Albers, Kristian Behrens ***
* Published in American Economic Review: Insights             ***
*****************************************************************
* 01/2025
* Stata
version 17.0

* This do file merges CBP employment to ZCTA data including shares of prime locations 
* at ZCTA area to validate our prime locations

* Use data
	import delimited "$temp/Data/US-CBSAs/ZCTA_PLshare.csv", clear

* Merge employment	
	tostring zcta, gen(ZCTA5CE20)
	merge 1:1 ZCTA5CE20 using "$data_USMETROS/Raw Numeric Data/CBP_ZCTA FILES/ZCTA_EMP"
 
* Compute employment density within ZCTAs 
	gen emp_dens = emp/zcta_area / 1000

* Aggregate densities to bins defined by shares of prime locations at ZCTA area 
	 gen sharebin = round(pl_coverage_share,0.1)*100
	 collapse (mean) Mean_dens = emp_dens (sd) SD_dens = emp_dens (count) N = emp_dens , by(sharebin)
	 gen SE_dens = SD_dens/sqrt(N)
	 gen CIU_dens = Mean_dens+SE_dens*1.96
	 gen CIL_dens = Mean_dens-SE_dens*1.96
 
* Plot correlation 
	twoway (scatter Mean_dens sharebin, color(black) ) (rcap CIU_dens CIL_dens sharebin , lcolor(black)) , ///
		xlabel(0(10)100) graphregion(color(white)) legend(off) ytitle("ZCTA employmetn density in K/km{superscript:2}") ///
		xtitle(Share of ZCTA covered by prime location in %) xsize(10) ysize(5)
* Write Appendix Figure B.2.3
	capture mkdir "$figures_App/US-CBSAs"
	graph export "$figures_App/US-CBSAs/FIG_B2_3_NETSdataValidation.pdf", replace
 
 * Script ends
